<!DOCTYPE html PUBLIC "-//IETF//DTD HTML 2.0//EN">
<?php
/*
require_once('extensions/Send2Wiki/libcurl/libcurlemu.inc.php');
function get_drupal_text_regex($html)
{
    $body_html = "Drupal conversion failed";

   // strip the chrome
   $match = array();
   preg_match('/<div id="main".*(<div class="content".*)<div class="links"/sm', $html, $match);
   if ($match) {
       $body_html = $match[1];
   }
}

function get_drupal_text_strpos($html)
{
    $body_html = "Drupal conversion failed";
   $main_pos = strpos( $html, '<div id="main"' );
   if ($main_pos != FALSE) {
      $content_pos = strpos( $html, '<div class="content"', $main_pos );
      if ($content_pos != FALSE) {
        $links_pos = strpos( $html, '<div class="links"', $content_pos );
        if ($links_pos != FALSE) {
          $body_html = substr( $html, $content_pos, ($links_pos - $content_pos) );
        } 
      }
   }
}

function get_contents_curl($uri)
{
	$ch = curl_init();
	$timeout = 5; // set to zero for no timeout
	curl_setopt ($ch, CURLOPT_URL, $uri);
	curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
	curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
	$file_contents = curl_exec($ch);
	curl_close($ch);
	return $file_contents;
}
*/
function get_contents( $uri ){
   $context = array('http' => array (
//   'header'=> 'User-agent: Send2Wiki 1.0',
   'header'=> "Connection: close\r\nAccept-Encoding: gzip\r\nUser-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.8.1.9) Gecko/20071025 Firefox/2.0.0.9\r\nAccept-Language: en-us,en;q=0.5\r\nAccept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7\r\nAccept: text/html", 
/*   'header'=> 'User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.8.1.9) Gecko/20071025 Firefox/2.0.0.9',
   'header'=> 'Accept-Language: en-us,en;q=0.5', 
   'header'=> 'Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7', 
   'header'=> 'Accept: text/html', 
*/   ),);
   
   $xcontext = stream_context_create($context);
   $contents = file_get_contents( $uri, FALSE, $xcontext );
   return $contents;
}


function multi_test_get($uri, $times, $method)
{
    $duration = 0;
    for ($time = 0; $time < $times; $time++)
    {
	    $start = microtime(true);
    	$content = get_contents($uri);
//		echo($content);
//		if ($method == "regex") get_drupal_text_regex($content);
//		else get_drupal_text_strpos($content);
    	$duration += (microtime(true) - $start);
    }
    echo($duration." - (".$method." - ".$times." times) ".$uri."<br/>");
    return $duration;
}

function compare_methods($uri, $times)
{
	$duration = multi_test_get($uri, $times, "regex");
//	$duration = multi_test_get($uri, $times, "strpos");
}
compare_methods("http://www.joelduffin.com/test2.php", 10);
compare_methods("http://mytec-t.twbtools.net/?q=node/197", 1);
compare_methods("http://mytec-t.twbtools.net/?q=node/197", 1);
compare_methods("http://mytec-t.twbtools.net/?q=node/197", 1);
compare_methods("http://mytec-t.twbtools.net/?q=node/197", 1);
compare_methods("http://mytec-t.twbtools.net/?q=node/197", 1);
compare_methods("http://mytec-t.twbtools.net/?q=node/197", 1);
compare_methods("http://mytec-t.twbtools.net/?q=node/197", 1);
compare_methods("http://mytec-t.twbtools.net/?q=node/197", 1);
compare_methods("http://mytec-t.twbtools.net/?q=node/197", 1);
compare_methods("http://mytec-t.twbtools.net/?q=node/197", 1);
compare_methods("http://mytec-t.twbtools.net/?q=node/197", 1);
compare_methods("http://mytec-t.twbtools.net/?q=node/197", 1);
compare_methods("http://mytec-t.twbtools.net/?q=node/197", 1);
compare_methods("http://mytec-t.twbtools.net/?q=node/197", 1);
compare_methods("http://mytec-t.twbtools.net/?q=node/197", 1);
//compare_methods("http://nlvm.usu.edu/", 1);
?>
